package com.mindskip.xzs.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mindskip.xzs.base.PageResult;
import com.mindskip.xzs.base.QueryPageBean;
import com.mindskip.xzs.domain.*;
import com.mindskip.xzs.repository.WJMapper;
import com.mindskip.xzs.service.*;
import com.mindskip.xzs.utility.ModelMapperSingle;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WJServiceImpl extends BaseServiceImpl<WJ> implements WJService {


    protected final static ModelMapper modelMapper = ModelMapperSingle.Instance();
    private final WJMapper wjMapper;

    @Autowired
    public WJServiceImpl(WJMapper wjMapper) {
        super(wjMapper);
        this.wjMapper = wjMapper;
    }

    @Override
    public void insertWj(WJ wj) {
        wjMapper.insertWj(wj);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();//获取当前页面
        Integer pageSize = queryPageBean.getPageSize();//获取每页显示的记录数
        String queryString = queryPageBean.getQueryString();//获取查询条件
        //分页插件，会在执行sql之前将分页关键字追加到SQL后面
        PageHelper.startPage(currentPage,pageSize);
        //调用持久层接口方法
        Page<WJ> page = wjMapper.findByCondition(queryString);
        //返回分页结果对象
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public int deleteByTwj(Integer id) {
        return wjMapper.deleteByTWj(id);
    }

    @Override
    public int updateByTwj(WJ wj) {
        return wjMapper.updateById(wj);
    }

}
